/*
 * Copyright 1997-2011
 *
 * http://www.pconline.com.cn
 *
 */
package cn.pconline.autoclub.util.ubb.node;

import java.util.Map;
import cn.pconline.autoclub.util.ubb.Node;

/**
 *
 * @author xhchen
 */
public class EmotNodeMobile extends AbstractNode {
	String emotRoot;
    Map<String, String> emotMap;

	public EmotNodeMobile() {}

	private EmotNodeMobile(String name, String attribute) {
		super.name = name;
		super.attribute = attribute;
	}

	public void setEmotRoot(String emotRoot) {
		this.emotRoot = emotRoot;
	}

    public void setEmotMap(Map<String, String> emotMap) {
        this.emotMap = emotMap;
    }

	@Override
	public StringBuilder getText(java.util.LinkedList<Node> stack) {
		StringBuilder sb = new StringBuilder();
//		boolean isAuto = SystemConstant.AUTO_APP_NAME.equals(EnvUtils.getEnv().getAppName());
		boolean isAuto = true;;
		//只有汽车网需要出表情,其余出文字
		if(isAuto){
			if ("em9001".equals(name)) {
	            sb.append('{').append(name).append('}');
	        } else {
	            sb.append("<img class=\"emot\" src=\"")
	                    .append(emotRoot)
	                    .append('/')
	                    .append(name)
	                    .append(emotMap.get(name.length() > 2 ? name.substring(2, name.length()) : "") != null ? ".png" : ".gif")
	                    .append("\"/>");
	        }
		}else{
			if(name.length() > 2 && emotMap.get(name.substring(2, name.length())) != null){
				sb.append("[");
				sb.append(emotMap.get(name.substring(2, name.length())));
				sb.append("]");
			}
			
		}
        
        
        return sb;
	}

	@Override
	public void appendText(CharSequence text) {}

	@Override
	public Node copyWithoutText() {
		EmotNodeMobile result = new EmotNodeMobile(name, attribute);
		result.setEmotRoot(emotRoot);
        result.setEmotMap(emotMap);
		return result;
	}

	@Override
	public Node build(String name, String attribute) {
		EmotNodeMobile result = new EmotNodeMobile(name, attribute);
		result.setEmotRoot(emotRoot);
        result.setEmotMap(emotMap);
		return result;
	}
}
